package base.Util;

import javafx.scene.image.Image;
import java.io.File;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class ImageCache {
    private static final int MAX_CACHE_SIZE = 100;
    private static final Map<String, Image> thumbnailCache = new ConcurrentHashMap<>();

    public static Image getThumbnail(File file) {
        String path = file.getAbsolutePath();
        return thumbnailCache.get(path);
    }

    public static void putThumbnail(File file, Image thumbnail) {
        if (thumbnailCache.size() >= MAX_CACHE_SIZE) {
            // 简单的缓存清理策略：清空缓存
            thumbnailCache.clear();
        }
        thumbnailCache.put(file.getAbsolutePath(), thumbnail);
    }

    public static void clearCache() {
        thumbnailCache.clear();
    }
}
